package com.project.finance.debit.controller;

import com.project.finance.common.po.TbDebitOrder;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.debit.service.DebitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 * 贷款订单管理
 *
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class DebitController {

    @Autowired
    private DebitService debitService;

//    查询所有用户的贷款订单信息
//    @RequestMapping(value = "/debitOrder",method = RequestMethod.GET)
//    public Result listSelect(){
//        List<TbDebitOrder> tbDebitOrders=debitService.listSelect();
//        return ResultGenerator.apiSuccess(tbDebitOrders);
//    }
//    查询所有用户的贷款订单信息
//    @RequestMapping(value = "/debitOrder",method = RequestMethod.GET)
//    public Result selectAll(){
//        List<TbDebitOrder> tbDebitOrders=debitService.selectAll();
//        return ResultGenerator.apiSuccess(tbDebitOrders);
//    }
    //修改用户的贷款订单信息
    @RequestMapping(value = "/debitOrder",method = RequestMethod.PUT)
    public Result update(@RequestBody TbDebitOrder tbDebitOrder){
        int update=debitService.update(tbDebitOrder);
        return ResultGenerator.apiSuccess(update);
    }
    //删除用户的贷款订单信息
    @RequestMapping(value = "/debitOrder",method = RequestMethod.DELETE)
    public Result delete(@RequestParam("debitOrderId") int debitorderid){
        int delete=debitService.delete(debitorderid);
        log.info("delete : " +delete);
        return ResultGenerator.apiSuccess(delete);
    }
    //增加用户的贷款订单信息
    @RequestMapping(value = "/debitOrder",method = RequestMethod.POST)
    public Result insertOrder(@RequestBody TbDebitOrder tbDebitOrder){
        int insert=debitService.insertOrder(tbDebitOrder);
        return ResultGenerator.apiSuccess(insert);
    }
    //分页
    @RequestMapping(value = "debitOrder",method = RequestMethod.GET)
    public ResultMsg listDebitOrderByPageCondition(@RequestParam("pageSize")int pageSize,
                                                   @RequestParam("pageNum")int pageNum){
        ResultMsg resultMsg = debitService.listDebitOrderByPage(pageSize, pageNum);
        resultMsg.setCode(0);
        return resultMsg;
    }
}
